﻿using System.Drawing;
using System.Windows.Forms;

namespace OpenSoftStore.Client.UIL.UserControls
{
    public class YhSoftTabControl : TabControl
    {
        public YhSoftTabControl()
            : base()
        {
            Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, 134);
            HotTrack = true;
            ItemSize = new Size(120, 30);
            Location = new Point(0, 0);
            Size = new Size(837, 526);
            DrawMode = TabDrawMode.OwnerDrawFixed;

            Padding = new Point(0, 0);
            Margin = new Padding(0);

            DrawItem += TbDrawItem;
        }

        private void TbDrawItem(object sender, DrawItemEventArgs e)
        {
            var backBrush = new SolidBrush(Color.White);
            var frontBrush = new SolidBrush(Color.Black);
            var stringF = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};
            for (int i = 0; i < TabPages.Count; i++)
            {
                Rectangle rec = GetTabRect(i);
                e.Graphics.FillRectangle(backBrush, rec);
                e.Graphics.DrawString(TabPages[i].Text, new Font("宋体", 9), frontBrush, rec, stringF);
            }

            Graphics g = e.Graphics;
            Rectangle endPageRect = GetTabRect(TabPages.Count - 1);
            var headerBackRect = new Rectangle(new Point(endPageRect.X + endPageRect.Width, endPageRect.Y),
                new Size(Width - endPageRect.X - endPageRect.Width, endPageRect.Height));
            Brush b = new SolidBrush(Color.White);
            g.FillRectangle(b, headerBackRect); 
        }
    }
}
